import type { postOrPutType } from "@/constants";
import type { HasId, IList, IResult } from "@/types/common";
import { getAxios, commonAxiosJson, deleteAxios } from "@/utils/request.ts";
/* 红包商城 商品信息 地址*/
const url = "/back/mall-goods";
/* 获取 商品信息 */
export const getMallGoodsInfo = <T, D>(params?: D): Promise<IResult<IList<T>>> => {
  return getAxios<IList<T>, D>(url, params);
};
/* 获取 商品详情信息 */
export const getMallGoodsByIdInfo = <T, D extends HasId>(params: D): Promise<IResult<T>> => {
  return getAxios<T, D>(url + "/" + params.id, params);
};
/* 新增，修改商品信息 */
export const commonMallGoodsInfo = <T, D>(params: D, type: postOrPutType): Promise<IResult<T>> => {
  return commonAxiosJson<T, D>(url, params, type);
};
/* 修改商品 状态 信息 */
export const putOnShelfInfo = <T, D>(params: D): Promise<IResult<T>> => {
  return commonAxiosJson<T, D>(url + "/change-status", params, "PUT");
};
/* 修改商品 排序 信息 */
export const putMallGoodsSortInfo = <T, D>(params: D): Promise<IResult<T>> => {
  return commonAxiosJson<T, D>(url + "/update-sort", params, "PUT");
};
/* 删除 商品信息 */
export const deleteMallGoodsInfo = <T, D>(params: D): Promise<IResult<T>> => {
  return deleteAxios<T, D>(url, params);
};
/* 获取七牛云上传token */
export const getUploadToken = <T, D>(params: D): Promise<IResult<T>> => {
  return getAxios<T, D>(url + "/get-up-token", params);
};
